package com.lms.collection.set;

import jdk.nashorn.internal.ir.CallNode;

import java.util.*;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-05-28 07:12
 * @Description:
 */
public class SetDemo {
    public static void main(String[] args) {
        Set<Object> set = new HashSet<>();
        //如果指定的元素不存在，则将其指定的元素添加（可选操作）。 返回false添加失败
        boolean add = set.add(1);
        add = set.add(1);
        set.clear();
        boolean b = set.addAll(Arrays.asList(1, 2, 3, 4));
        //从此集合中删除所有元素（可选操作）。
        boolean contains = set.contains(1);
        boolean empty = set.isEmpty();
        Iterator<Object> iterator = set.iterator();
        iterator.forEachRemaining(System.out::println);
        boolean remove = set.remove(1);
        boolean b1 = set.removeAll(Arrays.asList(2, 3));
        boolean b2 = set.retainAll(Arrays.asList(3, 4));
        set.forEach(System.out::println);
        int size = set.size();
        System.out.println(size);
        Spliterator<Object> spliterator = set.spliterator();
        //创建并行流
        Stream<Object> stream = StreamSupport.stream(spliterator, true);
        //等效于StreamSupport.stream(spliterator(), false);
        Stream<Object> stream1 = set.stream();
        //等效于StreamSupport.stream(spliterator(), true);
        Stream<Object> objectStream = set.parallelStream();
        // 返回一个包含此集合中所有元素的数组。
        Object[] objects = set.toArray();
        Integer[] integers = set.toArray(new Integer[0]);


    }
}
